package offer.singleLinkedList;

/**
 * Description：
 * Author: zhangc
 * Date：2017/7/18 23:25
 */
public class KthNodeTail15 {

    public static <T> T getKthTailReverse(LinkedList<T> list,int k){
        if (list == null || k <= 0)
            return null;
        LinkedList head = list;
        int i =0 ;
        for (; i < k && head != null; i++) {
            head = head.getNext();
        }
        if(i != k)
            return null;
        else {
            while (head != null){
                head = head.getNext();
                list = list.getNext();
            }
            return list.getValue();
        }
    }

}
